﻿
///////////////////////////////////////////////////////////////////////////////////
/// 文 件 名: NeedsOfBorrowerExtControl.cs
/// 作    者: XXD
/// 创建日期: 2012/6/18 9:48:18
/// 
///---------------------------------修改记录--------------------------------------
/// 修 改 人:          
/// 修改日期:
/// 修改原因: 
//////////////////////////////////////////////////////////////////////////////////
namespace ZX.WebApp.Crm.Workflow
{
    using System.Web;
    using ZX.BPM.Library;
    using System.Web.UI;

    /// <summary>
    ///  (借款，需求，报销)报销信息
    /// </summary>
    public partial class ReimbursementExpensesInfoControl : System.Web.UI.UserControl
    {
        #region 本地方法

        /// <summary>
        /// 设置只读
        /// </summary>
        /// <param name="isRead">是否只读</param>
        void SetReadonly(bool isRead)
        {
            txtReimbursementTotalAmount.ReadOnly = isRead;
            cmbReimbursementMode.Enabled = !isRead;
            cmbReimbursementType.Enabled = !isRead;
        }


        /// <summary>
        /// 获取字符参数
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="defaultValue">默认值</param>
        /// <returns>返回字符参数</returns>
        string GetStringFromQueryString(string key, string defaultValue)
        {
            string queryStringValue = HttpContext.Current.Request.QueryString[key];
            if (string.IsNullOrEmpty(queryStringValue))
            {
                return defaultValue;
            }

            return queryStringValue;
        }

        #endregion

        #region 外部接口

        /// <summary>
        /// 绑定数据
        /// </summary>
        /// <param name="data">数据源</param>
        /// <param name="toControl">是否同步到控件</param>
        public void Bind(NeedsOfBorrowerEdit data, bool setControl)
        {

            if (setControl)
            {
                txtReimbursementTotalAmount.Text = data.ReimbursementTotalAmount.ToString();
                cmbReimbursementMode.Text = data.ReimbursementMode;
                cmbReimbursementType.Text = data.ReimbursementType;
            }
            else
            {
                decimal reimbursementTotalAmount = 0;
                decimal.TryParse(txtReimbursementTotalAmount.Value.ToString(), out reimbursementTotalAmount);
                data.ReimbursementTotalAmount = reimbursementTotalAmount;

                data.ReimbursementMode = cmbReimbursementMode.Text;
                data.ReimbursementType = cmbReimbursementType.Text;
            }
        }

        bool readOnly = false;
        /// <summary>
        /// 是否只读
        /// </summary>
        public bool ReadOnly
        {
            set
            {
                SetReadonly(value);
                readOnly = value;
            }
            get
            {
                return readOnly;
            }
        }

      

        #endregion

        #region 事件处理

        protected void Control_Validation(object sender, DevExpress.Web.ASPxEditors.ValidationEventArgs e)
        {
            if (e.Value == null || string.IsNullOrEmpty(e.Value.ToString()))
            {
                e.IsValid = false;
                e.ErrorText = "必须填写";
                return;
            }

        }

        #endregion

      
    }
}